package cn.edu.xjtu.nbrash.xbarsuite;

import java.util.HashMap;
import java.util.Map;

import cn.edu.xjtu.nbrash.xbarsuite.floatbutton.RashFloatButton;
import cn.edu.xjtu.nbrash.xbarsuite.terry.EncodeContact;
import cn.edu.xjtu.nbrash.xbarsuite.terry.EncodeEmail;
import cn.edu.xjtu.nbrash.xbarsuite.terry.EncodePhone;
import cn.edu.xjtu.nbrash.xbarsuite.terry.EncodeSMS;
import cn.edu.xjtu.nbrash.xbarsuite.terry.EncodeText;
import cn.edu.xjtu.nbrash.xbarsuite.zxingdemo.RashResultDisplayTestActivity;
import cn.edu.xjtu.nbrash.xbarsuite.zxingdemo.ZXingDemo;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class RashActivity extends ListActivity {

	private String[] items;
	private Map<String, Intent> intents;

	private void initIntentsMap() {
		intents = new HashMap<String, Intent>();

		/*
		 * 注意： 各位写的功能使用this.putIntents(RSID, CLS)添加
		 * 参数RSID代表要在启动活动中显示的名称，CLS是你写的活动的类 参照如下例子
		 */
		this.putIntents(R.string.title_activity_hello_world, HelloWorld.class);

		/*
		 * 你所需要做的就是在这里调用一次this.putIntents
		 */

		this.putIntents(R.string.title_activity_zxing_demo, ZXingDemo.class);
		// @Terry
		this.putIntents(R.string.title_activity_encode_email, EncodeEmail.class);
		this.putIntents(R.string.title_activity_encode_phone, EncodePhone.class);
		this.putIntents(R.string.title_activity_encode_text, EncodeText.class);
		this.putIntents(R.string.title_activity_encode_sms, EncodeSMS.class);

		this.putIntents(R.string.title_activity_encode_contact,
				EncodeContact.class);

		this.putIntents(R.string.title_activity_rash_float_button,
				RashFloatButton.class);

		/**
		 * 测试扫描结果显示
		 */
		this.putIntents(R.string.title_activity_rash_result_display_test,
				RashResultDisplayTestActivity.class);

		/**
		 * 测试主界面
		 */
		this.putIntents(R.string.title_activity_rash_main,
				RashMainActivity.class);
	}

	private void putIntents(int rsid, Class<?> cls) {
		intents.put(getString(rsid), new Intent(this, cls));
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_rash);

		initIntentsMap();
		items = intents.keySet().toArray(new String[0]);
		setListAdapter(new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, items));
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.app.ListActivity#onListItemClick(android.widget.ListView,
	 * android.view.View, int, long)
	 */
	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		startActivity(intents.get(items[position]));
	}

}
